<template>
  <div>
    <div class="common_form_search">
      <el-form ref="searchForm" :inline="true" :model="searchForm">
        <el-form-item label="手机号">
          <el-input v-model="searchForm.mobile" maxlength="11" placeholder="请输入手机号" clearable @input="val => changeNumberInput(val)" />
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="searchForm.cert_name" placeholder="请输入真实姓名" clearable />
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="searchForm.nick_name" placeholder="请输入昵称" clearable />
        </el-form-item>
        <el-form-item label="城市">
          <el-input v-model="searchForm.city" placeholder="请输入城市" clearable />
        </el-form-item>
        <el-form-item label="注册时间">
          <my-date-picker ref="myDatePicker" />
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="search()">查询</el-button>
          <el-button size="small" @click="reset()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider />
    <div class="flex align-center table-top-btns">
      <h5 class="flex align-center">
        <svg-icon style="margin-right:15px" icon-class="list" :size="15" />数据列表
      </h5>
    </div>
    <el-table :data="tableData" border>
      <el-table-column align="center" prop="id" width="60" label="ID" />
      <el-table-column align="center" prop="create_time" label="注册时间" />
      <el-table-column align="center" prop="mobile" label="手机号">
        <template slot-scope="scope">
          {{ encryptPhoneNumber(scope.row.mobile) }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="cert_name" label="姓名" />
      <el-table-column align="center" prop="nick_name" label="昵称" />
      <el-table-column align="center" prop="gender" label="性别" />
      <el-table-column align="center" prop="city" label="城市" />
      <el-table-column align="center" prop="is_black" label="是否黑名单" />
      <el-table-column align="center" prop="money" label="会员来源" />
      <el-table-column align="center" prop="is_pay" label="是否支付" >
        <template slot-scope="scope">
          {{ scope.row.is_pay==1?'是':'否' }}
        </template>
      </el-table-column>
      
	  <el-table-column align="center" label="操作" width="280">
	    <template slot-scope="scope">
	      <el-button v-if="scope.row.is_black == '是'" type="warning" size="mini" @click="del_black(scope.row.mobile)">拉出黑名单
	      </el-button>
        <!-- <el-button size="mini" @click="set_money(scope.row.id)">设置押金
	      </el-button> -->
	    </template>
	  </el-table-column>
    </el-table>
    <custom-page ref="customPage" :total="total" @getList="getList" />
    <money ref="money"  @getList="getList" :order-id="selectedId" />
  </div>
</template>

<script>
import myDatePicker from '@/components/myDatePicker'
import customPage from '@/components/customPage'
import money from './components/moeny'
import { getUseList,delBlack } from '@/api/data'
export default {
  components: { myDatePicker, customPage,money },
  data() {
    return {
      searchForm: {
        mobile: '',
        cert_name: '',
        nick_name: '',
        create_time: '',
        city: ''
      },
      selectedId:'',
      tableData: [],
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    encryptPhoneNumber(phone) {
      const reg = /(\d{3})\d{4}(\d{4})/
      return String(phone).replace(reg, "$1****$2")
    },
    goToOrder(orderId) {
      if (orderId) {
        this.$router.push({ name: 'orderList', params: { orderId }})
      }
    },
	del_black(mobile){
		this.$confirm('是否确认拉出黑名单?', '提示', {
		  confirmButtonText: '确定拉',
		  cancelButtonText: '先不拉'
		})
		  .then(() => {
		    delBlack({mobile}).then(res => {})
		    this.getList()
		  })
		  .catch(() => { })
		
	},
  set_money(id){
    this.selectedId=id
    this.$refs.money.dialogVisible = true
  },
    // 查询
    search() {
      const pickerVal = this.$refs.myDatePicker.getVal()
      if (pickerVal !== 'error') {
        this.searchForm.create_time = pickerVal
        this.$refs.customPage.page = 1
        this.$refs.customPage.pageSize = 50
        this.getList()
      }
    },
    // 重置
    reset() {
      if (this.$refs.myDatePicker) {
        this.$refs.myDatePicker.reset()
      }
      this.searchForm = {
        mobile: '',
        template_id: '',
        send_status: '',
        create_time: '',
        shopname: ''
      }
      this.getList()
    },
    getList() {
      const { page, pageSize } = this.$refs.customPage
      getUseList({
        page,
        pageSize,
        ...this.searchForm
      }).then(res => {
        const { data, total } = res
        this.tableData = data || []
        this.total = total || 0
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.status_icon::before {
  display: inline-block;
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ff4146;
  margin-right: 6px;
}

.status_icon.success::before {
  background-color: #4ccb86;
}
</style>
